class Solution(object):
    def intervalIntersection(self, firstList, secondList):
        st = []
        n1 = len(firstList)
        n2 = len(secondList)
        left = 0
        right = 0
        while left < n1 and right < n2:
            if firstList[left][1] < secondList[right][0]:
                left += 1
            else:
                if firstList[left][0] > secondList[right][1]:
                    right += 1
                else:
                    min_value = max(firstList[left][0], secondList[right][0])
                    max_value = min(firstList[left][1], secondList[right][1])
                    st.append([min_value, max_value])
                    if firstList[left][1] == secondList[right][1]:
                        left += 1
                        right += 1
                    else:
                        if firstList[left][1] > secondList[right][1]:
                            right += 1
                        else:
                            left += 1
        return st


data = Solution()
firstList = [[0, 2], [5, 10], [13, 23], [24, 25]]
secondList = [[1, 5], [8, 12], [15, 24], [25, 26]]
print(data.intervalIntersection(firstList, secondList))
